import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/* Router Modules */
import serviceRouter from './modules/service'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/auth-redirect',
    component: () => import('@/views/login/auth-redirect'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '系统总览', icon: 'dashboard' }
    }]
  },
  {
    path: '/adaptive-data',
    redirect: 'https://baidu.com',
    component: Layout,
    name: 'AdaptiveData',
    meta: { title: 'AdaptiveData', icon: '5G' },
    children: [
      {
        path: 'https://baidu.com',
        meta: { title: '4/5G自适应认证数据' }
      }
    ]
  },

  // 一共需要4个部分，总览、认证数据、企业用户、个人用户
  {
    path: '/user-service-data',
    component: Layout,
    redirect: '/user-service-data/service-auth-data',
    name: 'UserServiceData',
    meta: { title: '用户认证服务数据', icon: 'user-auth-service' },
    children: [
      /* {
        path: 'service-data',
        component: () => import('@/views/userServiceData/ServiceData'),
        name: 'serviceData',
        meta: { title: '认证总览', icon: 'user-service-overview' }
      },*/
      {
        path: 'service-auth-data',
        component: () => import('@/views/userServiceData/ServiceAuthData'),
        name: 'serviceAuthData',
        meta: { title: '认证数据', icon: 'user-auth-data' }
      },
      /* {
        path: 'business-users',
        component: () => import('@/views/userServiceData/BusinessUsers'),
        name: 'businessUsers',
        meta: { title: '企业用户', icon: 'enterprise' }
      },*/
      {
        path: 'personal-users',
        component: () => import('@/views/userServiceData/PersonalUsers'),
        name: 'personalUsers',
        meta: { title: '个人用户', icon: 'personal-user' }
      }
    ]
  },

  {
    path: '/bio-auth-data',
    component: Layout,
    redirect: '/bio-auth-data/bio-auth-result',
    name: 'bioAuthData',
    meta: { title: '生物认证数据', icon: 'bio-auth' },
    children: [
      {
        path: 'bio-auth-result',
        component: () => import('@/views/bioAuthData/components/BioAuthResult'),
        name: 'bioAuthResult',
        meta: { title: '认证总览', icon: 'user-service-overview' }
      },
      {
        path: 'bio-auth-detail',
        component: () => import('@/views/bioAuthData/components/BioAuthData'),
        name: 'bioAuthDetail',
        meta: { title: '认证记录', icon: 'record' }
      }
    ]
  },
  /*
  {
    path: '/service-control',
    component: Layout,
    redirect: '/service-control/service-status',
    name: 'serviceControl',
    meta: { title: '服务控制', icon: 'service-control' },
    children: [
      {
        path: 'service-status',
        name: 'serviceStatus',
        component: () => import('@/views/serviceStatus/index'),
        meta: { title: '服务运行状态控制', icon: 'status' }
      },
      {
        path: 'service-config',
        name: 'serviceConfig',
        component: () => import('@/views/serviceConfig/index'),
        meta: { title: '服务配置信息管理', icon: 'config' }
      }
    ]
  },
  */
  {
    path: '/screen',
    component: Layout,
    redirect: '/screen-page',
    meta: { title: '大屏', icon: 'dashboard' },
    children: [
      {
        path: 'screen-page',
        name: 'ScreenPage',
        component: () => import('@/views/ScreenPage/index'),
        meta: { title: '展示' }
      }
      // ,
      /* {
        path: 'bar-show',
        name: 'BarShow',
        component: () => import('@/views/ScreenPage/components/BarShow'),
        meta: { title: '柱状图' }
      },
      {
        path: 'pie-show',
        name: 'PieShow',
        component: () => import('@/views/ScreenPage/components/PieShow'),
        meta: { title: '饼图' }
      },
      {
        path: 'line-show',
        name: 'LineShow',
        component: () => import('@/views/ScreenPage/components/LineShow'),
        meta: { title: '折线图' }
      }*/
    ]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

export const asyncRoutes = [
  serviceRouter,
  {
    path: 'about-us',
    component: Layout,
    children: [
      {
        path: 'https://ce.xidian.edu.cn/',
        meta: { title: '关于我们', icon: 'link' }
      }
    ]
  }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
